package com.tetris.project;


import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import engine.Score;

public class ShowScores extends ListActivity {
	
	ArrayList<Score> profileList;
	final String PROFILES_FILE = "/data/data/com.tetris.project/profiles";
	int profileIndex;
	HandleScores myScores;
	
	LinearLayout parentLayout;
	ListView myListView;
	ListAdapter myListAdapter;
	Score[] scores;
	String[] list;

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		Log.d(Shr_Res.TAG, "Start ShowScore.OnCreate");
		super.onCreate(savedInstanceState);
		myScores = new HandleScores(this);
		profileList = new ArrayList<Score>();
		
		
		//String[] scores = getResources().getStringArray(R.array.scores);
		//scores = new Score[10];
		//Log.d(Shr_Res.TAG, "chido");

/*		for (int i=0; i<10; i++){
			scores[i] = new Score();
		}
		for (int i=0; i<10; i++){
			scores[i].setName("Dummie");
		}
		for (int i=0; i<10; i++){
			scores[i].setScore(i+1);
		}
		Log.d(Shr_Res.TAG, "Done populating the array");
		
		for (int i=0; i<10; i++){
			Log.d(Shr_Res.TAG, scores[i].getName()+" "+String.valueOf(scores[i].getScore()));
		}
*/		
		//list = new String[10];
/*		for (int i=0; i<10; i++){
			list[i] = scores[i].getName()+" "+String.valueOf(scores[i].getScore());
		}
*/
		
		//setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
		//ListView myListView = getListView();
		Log.d(Shr_Res.TAG, "End ShowScore.OnCreate");
	}
	
	@Override
	public void onStart() {
		Log.d(Shr_Res.TAG, "Start ShowScore.OnStart");
		super.onStart();
		Log.d(Shr_Res.TAG, "End ShowScore.OnStart");
	}
	
	@Override
	public void onResume() {
		Log.d(Shr_Res.TAG, "Start ShowScore.OnResume");
		super.onResume();
		Log.d("Read File", "isScoreListEmpty = "+Shr_Res.isScoreListEmpty);
		profileList = myScores.readProfiles(profileList, PROFILES_FILE);
		if(Shr_Res.isScoreListEmpty){
			Toast.makeText(ShowScores.this, "Score List Empty!!", Toast.LENGTH_SHORT).show();
		}
		list = new String[profileList.size()];
		for ( int i = 0; i < profileList.size(); i++) {
			list[i] = profileList.get(i).getName()+" "+profileList.get(i).getScore();
		}
		for (int i=0; i<list.length; i++){
			Log.d(Shr_Res.TAG, list[i]);
		}
		for ( int i = 0; i < list.length; i++) {
			//setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list));
			setListAdapter(new ArrayAdapter<String>(this, R.layout.score_list, list));
		}
		Log.d(Shr_Res.TAG, "End ShowScore.OnResume");
	}
	
	@Override
	public void onPause() {
		Log.d(Shr_Res.TAG, "Start ShowScore.OnPause");
		super.onPause();
		Log.d(Shr_Res.TAG, "End ShowScore.OnPause");
	}
	
	@Override
	public void onStop() {
		Log.d(Shr_Res.TAG, "Start ShowScore.OnStop");
		super.onStop();
		Log.d(Shr_Res.TAG, "End ShowScore.OnStop");
	}
	
	@Override
	public void onDestroy() {
		Log.d(Shr_Res.TAG, "Start ShowScore.OnDestroy");
		super.onDestroy();
		Log.d(Shr_Res.TAG, "End ShowScore.OnDestroy");
	}
	
/*	private class HandleScores extends View {

		
		
		public HandleScores(Context context) {
			super(context);
		}
	}
*/	
}